﻿
@{
    ViewBag.Title = "UserList";
    Layout = "~/Areas/Admin/Views/Shared/_Layout.cshtml";
    var data = ViewBag.UserList as List<LuDragon.Data.Entities.Sys_User>;
    var roleData = ViewBag.RoleList as List<LuDragon.Data.Entities.Sys_Role>;
}


<span class="layui-breadcrumb">
    <a>系统设置</a>
    <a>用户管理</a>
    <a><cite>列表</cite></a>
</span>
<hr />
<button class="layui-btn" onclick="location.href='UserEdit'"><i class="layui-icon">&#xe654;</i>新增</button>
<div class="table-list layui-form">
    <table class="layui-table layui-list-table">
        <thead>
            <tr>
                <th>用户名</th>
                <th>姓名</th>
                <th>性别</th>
                <th>电话</th>
                <th>邮箱</th>
                <th>注册日期</th>
                <th>是否启用</th>
                <th>所属角色</th>
                <th>操作</th>
            </tr>
        </thead>
        <tbody>
            @for (int i = 0; i < data.Count; i++)
            {
                <tr>
                    <td><span class="layui-table-bd">@data[i].UserName</span></td>
                    <td><span class="layui-table-bd">@data[i].CnName</span></td>
                    <td><span class="layui-table-bd">@data[i].Sex</span></td>
                    <td><span class="layui-table-bd">@data[i].Phone</span></td>
                    <td><span class="layui-table-bd">@data[i].Email</span></td>
                    <td><span class="layui-table-bd">@data[i].RegisterTime</span></td>
                    <td><span class="layui-table-bd">@(data[i].Enabled == true ? "是" : "否")</span></td>
                    <td>
                        @for (int j = 0; j < roleData.Count; j++)
                        {
                            if (roleData[j].RoleId == data[i].RoleId)
                            {
                                <span class="layui-table-bd">@roleData[j].RoleName</span>
                                break;
                            }
                        }
                    </td>
                    <td class="layui-table-btn">
                        <button title="编辑" class="layui-btn layui-btn-normal layui-btn-small" onclick="location.href='UserEdit?id=@data[i].UserId'">
                            <i class="layui-icon">&#xe642;</i>
                        </button>
                        @if (!data[i].IsSystem)//非系统用户
                        {
                            if (data[i].Enabled)//启用状态
                            {
                                <button title="禁用" class="layui-btn layui-btn-warm layui-btn-small" onclick="Disabled(@data[i].UserId)">
                                    <i class="layui-icon">&#x2718;</i>
                                </button>
                            }
                            else
                            {
                                <button title="启用" class="layui-btn layui-btn-small" onclick="Enabled(@data[i].UserId)"><i class="layui-icon">&#x2714;</i></button>
                            }
                            <button title="删除" class="layui-btn layui-btn-danger layui-btn-small" onclick="Del(@data[i].UserId);"><i class="layui-icon">&#xe640;</i>
                        </button>
                        }
                    </td>
                </tr>
            }
        </tbody>
    </table>
</div>
<script>
    function Del(id) {
        dialog.dialog("删除操作不可恢复，您确认要删除吗？", function () {
            $.post("Del", { "id": id }, function (result) {
                var data = JSON.parse(result);
                if (data.Code == 200) {
                    location.reload();
                } else {
                    dialog.prompt("操作失败，请稍后重试。");
                }
            })
        });
    }
    //启用
    function Enabled(id) {
        dialog.dialog("是否启用此用户？", function () {
            $.post("Enabled", { "userId": id }, function (result) {
                var data = JSON.parse(result);
                if (data.Code == 200) {
                    location.reload();
                } else {
                    dialog.prompt("操作失败，请稍后重试。");
                }
            })
        });
    }
    //禁用
    function Disabled(id) {
        dialog.dialog("是否禁用此用户？", function () {
            $.post("Disabled", { "userId": id }, function (result) {
                var data = JSON.parse(result);
                if (data.Code == 200) {
                    location.reload();
                } else {
                    dialog.prompt("操作失败，请稍后重试。");
                }
            })
        });
    }
</script>



